(function (){
　　"use strict";
	
 
//手机导航展开特效
$(function(){
$("#m_nav .title .list").css({"opacity":"1","visibility":"visible"});
$("#m_nav .title .a").click(function(){
   var tt = $(this).parents(".title");
  if ($(tt).hasClass('on')) {
	  $(tt).children(".list").slideUp(600); //展开
	  $(tt).removeClass("on"); 
	}else{
	  $("#m_nav .title ").removeClass("on");
	  $("#m_nav .title .list").slideUp();
	  $(tt).children(".list").slideDown();
	  $(tt).toggleClass("on"); 
	}
});
$("#nav_btn_box").click(function(){
  $("#nav_btn_box .point").toggleClass("on"); 
  $("#nav_btn_box").toggleClass("on"); 
  $("#m_nav").toggleClass("act");
  $(".nav_mask").fadeToggle();
});

$(".nav_mask").click(function(){
$("#nav_btn_box .point").removeClass("on"); 
$("#nav_btn_box").removeClass("on"); 
$(this).fadeToggle();
$(".nav_btn_box").removeClass("act");
$("#m_nav").removeClass("act");
});


});	
 

$('.tc_btn[name]').click(function() {
    var tf_name_id = $(this).attr('name');
    $('.tc[name=' + tf_name_id + ']').addClass('act');
});
$('.tc_close').click(function() {
    $(this).parents('.tc').removeClass('act');
});
$('.tc_bg').click(function() {
    $(this).parents('.tc').removeClass('act');
});

//banner切换
$(".banner_slider").on('init', function(event, slick, currentSlide, nextSlide){
    $(".banner_slider li").first().removeClass("slick-current");
    setTimeout(function(){
        $(".banner_slider li").first().addClass("slick-current");
    },1);
});

 $('.banner_slider').init(function(slick){
    $('.banner_slider li.slick-current').addClass('active').siblings().removeClass('active');
})
$('.banner_slider').on('afterChange',function(slick,currentSlide){
    $('.banner_slider li.slick-current').addClass('active').siblings().removeClass('active');
})
$('.banner_slider').on('beforeChange',function(event, slick, currentSlide, nextSlide){
    $(".fenzi").html(nextSlide + 1);
$(".fenmu").html(slick.slideCount);
    $('.banner_slider li.slick-current').addClass('remove').siblings().removeClass('remove');
    setTimeout(function(){
        $('.banner_slider li').removeClass('remove')
    },500)
})

$('.banner_slider').slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
arrows:false,
infinite: true,//循环播放
speed: 1000,
fade: true,
pauseOnHover: false,
autoplay: true,
autoplaySpeed:7000,
appendDots:'.slickdotbox',
});

$(window).scroll(function(){
    var winHeight=$(this).scrollTop()
    if(winHeight>1){
           $('#header').addClass('xg')
       }else{
           $('#header').removeClass("xg")
       }
     if ($(this).scrollTop()>300){
         $("#gotop").removeClass("hide");
     }else{
         $("#gotop").addClass("hide");
     }
 });

 $('#gotop').click(function () {
     $('html,body').animate({
         scrollTop : '0px'
     }, 800);
 });

 $('#s_jishu ul').slick({
    slidesToShow: 4,
    slidesToScroll: 1,
    arrows: false,
    dots: false,
    speed: 700,
    touchThreshold:20,
    autoplay: true,
    autoplaySpeed: 3000,
     responsive: [
      {
        breakpoint: 992,
        settings: {
          slidesToShow:3,
        }
      },
      {
        breakpoint:640,
        settings: {
          slidesToShow:2,
        }
      },
    ]
  });

  $('#s_pro ul').slick({
    slidesToShow: 4,
    slidesToScroll: 1,
    arrows: true,
    dots: false,
    speed: 700,
    // infinite:true,
    touchThreshold:20,
    // autoplay: true,
    // autoplaySpeed: 3000,
     responsive: [
      {
        breakpoint: 992,
        settings: {
          slidesToShow:3,
        }
      },
      {
        breakpoint:640,
        settings: {
          slidesToShow:2,
        }
      },
    ]
  });

 

//友情链接
$("#bnt_link1").click(function(){
    $(this).toggleClass("icon_un");
    $("#content_link1").slideToggle(200);
});
$(function(){$('a[href*="#"],area[href*="#"]').click(function(){if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'')&&location.hostname==this.hostname){var $target=$(this.hash);$target=$target.length&&$target||$('[name='+this.hash.slice(1)+']');if($target.length){var targetOffset=$target.offset().top;$('html,body').animate({scrollTop:targetOffset},600);return false}}})});

$(window).scroll(function(){
    if ($(this).scrollTop()>300){
        $("#gotop").removeClass("hide");
    }else{
        $("#gotop").addClass("hide");
    }
});
$('#gotop').click(function () {
    $('html,body').animate({
        scrollTop : '0px'
    }, 800);
});

$("#bnt_sub_nav").click(function(){
    $(this).toggleClass("on");
    $("#sub_nav_content").slideToggle();
});

 
//标题分割动画	
let w = document.body.offsetWidth || document.body.clientWidth;
let h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
const _ = function (select) { return document.querySelector(select) };
const _$ = function (select) { return document.querySelectorAll(select)};
const clickEvent = (function() {
    if ('ontouchstart' in document.documentElement === true){
        return 'touchstart';
    }else{
        return 'mousedown';
    }
})();
const getScrollbarWidth = function() {
    const container = document.createElement('div');
    container.style.visibility = 'hidden';
    container.style.position = 'absolute';
    container.style.left = '-9999px';
    container.style.width = '100px';
    container.style.overflow = 'scroll';
    document.body.appendChild(container);
    const containerWidth = container.offsetWidth;
    const inner = document.createElement('div');
    inner.style.width = '100%';
    container.appendChild(inner);
    const innerWidth = inner.offsetWidth;
    container.parentNode.removeChild(container);
    return containerWidth - innerWidth;
};

const scrollMarginRightTrue = function(){
    if ('ontouchstart' in document.documentElement === false){
        _('html').style.marginRight = getScrollbarWidth() + 'px';
        _('header').style.width =_('header').offsetWidth + 'px';
        document.documentElement.style.overflowY='hidden';
    }
}
const scrollMarginRightFalse = function(){
    if ('ontouchstart' in document.documentElement === false){
        _('html').style.marginRight = 0;
        document.documentElement.style.overflowY = 'scroll';
    }
}
const splitlist = function(splitlist,bool){
    Array.prototype.forEach.call(_$(splitlist), function (item) {
        let flag = false,
            isRandom = bool,
            delays = parseInt(item.getAttribute('delay')),
            speeds = parseInt(item.getAttribute('speed')),
            Arrays = item.innerHTML.replace(/<br>/g, "\n").replace(/<i>/g, "\\").replace(/<\/i>/g, "\t").replace(/&amp;/g, "&").split("");
        item.innerHTML = '';
        if(!delays){
            delays = 100;
        }
        if(!speeds){
            speeds = 100;
        }
        Array.prototype.forEach.call(Arrays,function(letter, i) {
            let span = document.createElement("span"),
                br = document.createElement("br"),
                random = 1;
            if(letter.indexOf("\n") >= 0){
                item.appendChild(br);
                return;
            }
            if(letter.indexOf("\\") >= 0){
                flag = true;
                return;
            }
            if(letter.indexOf("\t") >= 0){
                flag = false;
                return;
            }
            if(flag){
                span.className = 'letters';
            }
            if(isRandom){
                random = Math.random();
            }
            delays += speeds;
            span.style.animationDelay = delays * random  + 'ms';
            span.innerHTML = letter;
            item.appendChild(span);
        });
    });
};
function scrollAnimate() {
    const viewHeight =window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;    
    Array.prototype.forEach.call(_$('.flags'),function(slider){
        const top = slider.getBoundingClientRect().top;
        if (top + 100 <= viewHeight ) {
            slider.classList.add('flag');
        }
    });
    Array.prototype.forEach.call(_$('.photoActives'),function(slider){
        const top = slider.getBoundingClientRect().top;
        if (top + 100 <= viewHeight ) {
            slider.classList.add('reset_photoActive');
        }
    });
    Array.prototype.forEach.call(_$('.itemAnimates'),function(slider){
        const top = slider.getBoundingClientRect().top;
        if (top + 100 <= viewHeight ) {
            slider.classList.add('animates');
        }
    });
};
//图片动画
function photoActives(){
    let photoActives = _$('.photoActives');
    let section = document.createElement('section');
    section.classList.add('photoActive');
    if(!photoActives){
        return
    }
    for(let i = 0 ;i < photoActives.length; i++){
        photoActives[i].appendChild(section.cloneNode());
    }
};

function itemAnimates(){
    let itemAnimates = _$(".itemAnimates");
    if(!itemAnimates){return}
    for (let i = 0; i < itemAnimates.length; i++) {
      let itemAnimate = itemAnimates[i].querySelectorAll('.itemAnimate');
      let delay = 0;
      for (let j = 0; j < itemAnimate.length; j++) {
        if(itemAnimates[i].getAttribute('random') == '1'){
            delay = Math.random() * itemAnimates[i].getAttribute('randomMax');
          }else{
            delay += 300;
          }
          itemAnimate[j].style.animationDelay = delay + "ms";
      }
    }
};

function newspaper(){
    Array.prototype.forEach.call(_$('.newspaper table'), function(el) {
        let section = document.createElement('section');
        section.className = 'tablebox';
        el.parentNode.replaceChild(section, el);
        section.appendChild(el);
    });
    Array.prototype.forEach.call(_$('.newspaper img'), function(el) {
        let section = document.createElement('section');
        section.className = 'photoActives';
        el.parentNode.replaceChild(section, el);
        section.appendChild(el);
    });
};
	
scrollAnimate();
photoActives();
splitlist('.splitlist',false);
window.addEventListener('scroll',function(){
    scrollAnimate();
});
	
　　// some code here
})();
